const mongoose = require('mongoose')

const JournalSchema = new mongoose.Schema({
    userId:{ //操作人id
        type: mongoose.SchemaTypes.ObjectId,
        ref:'User',
    },
    taskId:{ //任务id
        type: mongoose.SchemaTypes.ObjectId,
        ref:'Task'
    },
    taskname:{
        type:String,
    },
    // creator: { //发起人/审核人
    //     type: mongoose.SchemaTypes.ObjectId,
    //     ref: 'User'
    // },
    worker: [{ //执行人/通知人
        type: mongoose.SchemaTypes.ObjectId,
        ref: 'User'
    }],
    operate: { //操作名称 0提交 1更新 2分解 3删除 4通过审核 5打回 6神秘
        type:Number,
        enum:[0,1,2,3,4,5,6],
        required:true
    },
    describe:{ //保存描述
        type:String
    },
    oldData:{ //旧数据
        type: Array
    },
    newData:{ //新数据 
        type: Array
    },
    isRead: { //是否已读 true已读 false未读
        type: Boolean,
        default: false
    }
}, {
    // 创建时间和更新时间
    timestamps: true
})

module.exports = mongoose.model('Journal', JournalSchema, 'journal')